package com.dd.servlet;

import com.dd.domain.Product;
import com.dd.service.ProductService;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class ShopAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        int pageNum = Integer.parseInt(request.getParameter("d01")) * 5;
        ProductService ps = new ProductService();
        List<Product> data = ps.findByLimit(pageNum,5);
        Gson gson=new Gson();
        String product = gson.toJson(data);
        System.out.println(product);
        response.setContentType("text/json;charset=UTF-8");
        response.getWriter().write(product);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
